<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="utf-8">
    <title>lwx的系统</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta http-equiv="Access-Control-Allow-Origin" content="*">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="format-detection" content="telephone=no">
    <link rel="icon" href="/favicon.ico">
    <link rel="stylesheet" href="/layui/css/layui.css" media="all" />
    <link rel="stylesheet" href="/css/index.css" media="all" />
</head>
<body class="childrenBody">

<blockquote class="layui-elem-quote quoteBox">
    <form class="layui-form" id="searchFrm" method="post">
        <div class="layui-form-item" style="text-align: center">
            <div class="layui-inline">
                <label class="layui-form-label">登录名称</label>
                <div class="layui-input-inline">
                    <input type="text" name="loginname"  autocomplete="off" class="layui-input">
                </div>
            </div>
            <div class="layui-inline">
                <label class="layui-form-label">开始时间</label>
                <div class="layui-input-inline">
                    <input type="text" name="startTime" id="startTime"  autocomplete="off" class="layui-input">
                </div>
            </div>

            <div class="layui-inline">
                <label class="layui-form-label">结束时间</label>
                <div class="layui-input-inline">
                    <input type="text" name="endTime" id="endTime" autocomplete="off" class="layui-input">
                </div>
            </div>

            <div class="layui-inline">

                <button  type="button" class="layui-btn" id="doSearch"><span class="layui-icon">&#xe615;</span>搜索</button>
                <button type="reset" class="layui-btn layui-btn-danger"><span class="layui-icon">&#xe669;</span>重置</button>
            </div>


        </div>


    </form>
</blockquote>
<!--表格-->
<table id="loginfoTable"  class="layui-table" lay-filter="loginfoTable"></table>

<!--头部工具栏-->
<div id="loginfoTableToolBar" style="display: none">
    <a class="layui-btn layui-btn-sm" lay-event="batchdel"><span class="layui-icon">&#xe640;</span>批量删除</a>


</div>
<!--操作-->
<div id="loginfoTableRowBar" style="display: none">

    <a class="layui-btn layui-btn-xs layui-btn-danger" lay-event="del">删除</a>

</div>

</body>

<script type="text/javascript" src="/layui/layui.js"></script>


<script>
    layui.use(['table','form','layer','laydate','jquery'],function () {

        var table = layui.table;
        var form = layui.form;
        var layer = layui.layer;
        var laydate =layui.laydate;
        var $=layui.jquery;

        laydate.render({
            elem:'#startTime',
            type:'datetime'
        });

        laydate.render({
            elem:'#endTime',
            type:'datetime'
        });

        var tableIns=table.render({
            elem: '#loginfoTable'
            ,url:'/loginfo/loadAllLoginfo'
            ,toolbar: '#loginfoTableToolBar' //开启头部工具栏，并为其绑定左侧模板
            ,defaultToolbar: ['filter', 'exports', 'print', { //自定义头部工具栏右侧图标。如无需自定义，去除该参数即可
                title: '提示'
                ,layEvent: 'LAYTABLE_TIPS'
                ,icon: 'layui-icon-tips'
            }]
            ,title: '日志数据表'
            ,height:'full-150'
            ,cols:
                [
                    [
                        {type: 'checkbox', fixed: 'left'}
                        ,{field:'id', title:'ID', width:200, fixed: 'left', unresize: true, sort: true,align:'center'}
                        ,{field:'loginname', title:'登录名称', width:200, edit: 'text' ,align:'center'}

                        ,{field:'loginip', title:'登录IP', width:200, edit: 'text', sort: true ,align:'center'}
                        ,{field:'logintime', title:'登录时间', width:230 ,align:'center'}

                        ,{fixed: 'right', title:'操作', toolbar: '#loginfoTableRowBar', width:200 ,align:'center'}
                    ]
                ]
            ,page: true
        });
        $("#doSearch").click(function () {
            //收集用户数据 使用jquery
            var params = $("#searchFrm").serialize();
            // alert(params);
            tableIns.reload({
                url:"/loginfo/loadAllLoginfo?"+params,
                page:{
                    curr: 1
                }
            })
        });

        //监听表头事件
        table.on('toolbar(loginfoTable)', function(obj){

            switch(obj.event){
                case 'batchdel':
                    //layer.msg('添加');
                    batchDelete(obj);
                    break;

            };
        });

        function batchDelete(obj){
            var checkStatus=table.checkStatus('loginfoTable');
            // console.log(checkStatus.data);//获取选中行的数据
            // console.log(checkStatus.data.length);//获取选中行数量
            if(checkStatus.data.length==0){

                layer.msg("请选择要删除的行")
            }else{
                layer.confirm('真的要删除选中行么',function (index) {
                    layer.close(index);
                    var params="";
                    $.each(checkStatus.data,function (i,item) {
                        if(i==0){
                            params +="ids="+item.id;
                        }else{
                            params +="&ids="+item.id;
                        }
                    });
                    //alert(params);

                    //向后台发请求删除
                    $.post("/loginfo/batchDeleteLoginfo",params,function (obj) {
                        if(obj.code==200) {
                            //刷新表格
                            tableIns.reload();
                        }
                        layer.msg(obj.msg);
                    })
                })
            }
        }

        //监听行按钮事件
        //监听工具条
        table.on('tool(loginfoTable)', function(obj){ //注：tool 是工具条事件名，test 是 table 原始容器的属性 lay-filter="对应的值"
            var data = obj.data; //获得当前行数据
            var layEvent = obj.event; //获得 lay-event 对应的值（也可以是表头的 event 参数对应的值）
            // alert(data.id);
            if(layEvent === 'del'){ //删除
                layer.confirm('真的删除该行么', function(index){

                    layer.close(index);
                    //向服务端发送删除指令
                    $.delete("/loginfo/deleteLoginfo",{id:data.id},function (obj) {
                        if(obj.code==200) {
                            //刷新表格
                            tableIns.reload();
                        }
                        layer.msg(obj.msg);
                    });
                });
            }
        });
    })
</script>
</html>